package com.mask.mk.controller;


import com.mask.mk.service.GoodsService;
import com.mask.mk.util.JsonResult;
import com.mask.mk.vo.goods.QueryByMultReq;
import com.mask.mk.vo.goods.UploadGoodsRequest;
import com.mask.mk.vo.goods.UploadGoodsResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author joey
 * @since 2023-04-25
 */
@Api(tags = "商品操作")
@RestController
@RequestMapping("/goods")
public class GoodsController {



    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "管理员-上传商品")
    @PostMapping("/uploadGoods")
    public JsonResult uploadGoods(@RequestParam(value = "file") MultipartFile file,
                                  @RequestParam(value = "typeId") int typeId,
                                  @RequestParam(value = "goodsName") String goodsName,
                                  @RequestParam(value = "detailName") String detailName,
                                  @RequestParam(value = "goodsPrice") int goodsPrice,
                                  @RequestParam(value = "goodsCode") String goodsCode,
                                  @RequestParam(value = "goodsNum") int goodsNum,
                                  @RequestParam(value = "goodsStatus") int goodsStatus,
                                  @RequestParam(value = "goodsDescribe") String goodsDescribe){
        UploadGoodsRequest goodsRequest = new UploadGoodsRequest();
        goodsRequest.setDetailName(detailName)
        .setFile(file).setGoodsCode(goodsCode)
                .setGoodsDescribe(goodsDescribe)
                .setGoodsName(goodsName)
                .setGoodsNum(goodsNum)
                .setGoodsPrice(goodsPrice)
                .setGoodsStatus(goodsStatus)
                .setTypeId(typeId);
        return goodsService.insertUpdateGoods(goodsRequest);
    }
    @ApiOperation(value = "前台-获取商品列表")
    @PostMapping("/getGoodsList")
    public JsonResult uploadGoods(){
        return goodsService.getGoodsList();
    }

    @ApiOperation(value = "前台-查看商品详情")
    @PostMapping("/queryOne")
    public JsonResult queryOne(@RequestBody UploadGoodsRequest uploadGoodsRequest){
        if(uploadGoodsRequest.getGoodsId() != 0){
            return goodsService.getGoodsById(uploadGoodsRequest.getGoodsId());
        }else{
            return JsonResult.fail("获取id为空");
        }
    }

    @ApiOperation(value = "多条件查询")
    @PostMapping("/queryByMut")
    public JsonResult queryByMut(@RequestBody UploadGoodsRequest uploadGoodsRequest){
        System.out.println(" 查询条件 => "+uploadGoodsRequest);
        return goodsService.getGoodsByMultipleConditions(uploadGoodsRequest);
    }

    @ApiOperation(value = "分类查询")
    @PostMapping("/queryByType")
    public JsonResult queryByType(@RequestBody QueryByMultReq query){
        System.out.println(" 查询条件 => "+query);
        return goodsService.getGoodsByGroup(query);
    }




}

